package com.itheima.properties;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Scanner;
import java.util.Set;

public class Test {
    public static void main(String[] args) throws IOException {
        /*Properties prop = new Properties();
        //使用properties将本地文件信息读取到集合中
        BufferedReader br = new BufferedReader(new FileReader("test_io流\\test.properties"));
        prop.load(br);
        br.close();*/

        //此类可以大大简化代码无需再自己创建流,但本地文件必须在src文件下
        ResourceBundle rb = ResourceBundle.getBundle("bundle");//无需加入后缀直接写文件名即可

        Scanner sc = new Scanner(System.in);
        System.out.println("输入用户名:");
        String userName = sc.next();
        System.out.println("请输入密码:");
        String word = sc.next();

        if (rb.containsKey(userName)) {
            String passWord = rb.getString(userName);
            if(word.equals(passWord)){
                System.out.println("登录成功");
            }
        }else {
            System.out.println("用户名或密码错误");
        }
        /*Set<String> allName = prop.stringPropertyNames();
        for (String name : allName) {
            String passWord = prop.getProperty(name);
            if(userName.equals(name)&&word.equals(passWord)){
                System.out.println("欢迎回来");
            }else{
                System.out.println("你有问题");
            }
        }*/
       /* if(prop.containsKey(userName)){
            String passWord = prop.getProperty(userName);
            if(word.equals(passWord)){
                System.out.println("登录成功");
            }
        }else {
            System.out.println("用户名或密码错误");
        }*/
    }
}
